/*
* @Author: majingyu
* @Date:   2017-05-23 19:12:11
* @Last Modified by:   jingyu.ma
* @Last Modified time: 2017-08-06 13:33:56
*/
import React, { Component }from 'react';
import { connect } from 'react-redux';
import MyInviteList from 'components/myInviteList.jsx';
import { eidtServiceTab, getMyList, changeHistoryPageType,clickTips, eidtSkillInfoAction,accectOrder,rejectOrder } from 'action/service';
import { changeOrderDetailId } from 'action/orders.js';
import 'css/components/tabs.less';
import { changeCommentId } from 'action/commont.js';

class OrderLists extends Component {
    constructor(props) {
        super(props);
        this.state = {
           active: 'myDemandList' 
        }
        this.props.changeHistoryPage();
    } 
    componentDidMount(){
        if(this.state.active == 'myDemandList'){
            console.log("hrere");
            this.getList(1);
        }else{
            this.getList(2);
        }
    }
    getList(status,page){
        console.log("herre111");
        let data= {
            pageNumber: page || this.props.services.nearListList.pageNo,
            pageSize: 10,
            from:status,
            status:1
        }
        this.props.getList(data);
    } 
    changeActive(status,tabName){
        let active = status == 1?'myDemandList':'mySkillList';
        this.setState(Object.assign({},this.state,{
            active: active
        }))
        this.getList(status);
    }
    getMoreList(){
        if(this.state.active == 'myDemandList'){
            this.getList(1,this.props.services.nearListList.pageNo+1);
        }else{
            this.getList(2,this.props.services.nearListList.pageNo+1);
        }
    }
    goToDetail(id){
        this.props.goToDetailPage(id);
        window.location.href = '#/orderDetail';
    }
    clickTips(id){
        let params = {
            id: id
        }
        this.props.dispatch(addTips(params));
    }
    accept(id){
        let params = {
            orderId: id
        }
        this.props.accept(params);
    }
    reject(id){
        let params = {
            orderId: id
        }

        this.props.reject(params);
    }

    render(){
        let self = this;
        return (
            <div className="content">
                <ul className="subNavWrap">
                    <li key='myDemandList' onClick={()=>{this.changeActive(1,'myDemandList')}} className={this.state.active == 'myDemandList'?'active':''}>约需求</li>
                    <li key='mySkillList' onClick={()=>{this.changeActive(2,'mySkillList')}} className={this.state.active == 'mySkillList'?'active':''}>约技能</li>
                </ul>
                <MyInviteList getMyInviteList={this.props.services.getMyInviteList} accept={(id) => {this.accept(id)}} reject={(id) => {this.reject(id)}} getMoreList={()=>{this.getMoreList()}}/>
            </div>
        );
    }
}


const NearByData = (state) => {
    return {
        app:state.app,
        services: state.services,
        skill:state.skill,
        user: state.user
    }
}
let dispatchHandle = (dispatch, getState) => {
    return {
        getList(data){
            dispatch(getMyList(data));
        },
        changeCommentId(id){
            dispatch(changeCommentId(id));
        },
        goToDetailPage(id){
            dispatch(changeOrderDetailId(id));
        },
        changeHistoryPage(){
            dispatch(changeHistoryPageType(2));
        },
        accept(data){
            dispatch(accectOrder(data))
        },
        reject(data){
            dispatch(rejectOrder(data));
        }
    }
    
}
let visibileNearBy= connect(NearByData, dispatchHandle)(OrderLists);


export default visibileNearBy;